package com.zzzy.doc.controller;

import com.zzzy.common.vo.AjaxResult;
import com.zzzy.common.vo.PageResult;
import com.zzzy.doc.dao.entity.DocNotifyMessage;
import com.zzzy.doc.dao.entity.Document;
import com.zzzy.doc.service.DocNotifyMessageService;
import com.zzzy.doc.vo.notify.DocNotifyMessagePageReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;


/**
 * Description: 提醒消息
 *
 * @author fc
 * @date 2024/9/4
 */
@Tag(name = "提醒消息", description = "doc600")
@Validated
@RestController
@RequestMapping("/doc/notifyMessage")
public class DocNotifyMessageController {

    @Resource
    private DocNotifyMessageService docNotifyMessageService;

    @Operation(summary = "分页列表")
    @GetMapping(value = "/page")
    public AjaxResult<PageResult<DocNotifyMessage>> page(@Valid @ParameterObject DocNotifyMessagePageReq queryReq) {
        PageResult<DocNotifyMessage> docNotifyMessagePage = docNotifyMessageService.getDocNotifyMessagePage(queryReq);
        return AjaxResult.success(docNotifyMessagePage);
    }

    @Operation(summary = "标记消息已读")
    @PutMapping("/markNotifyMessageRead/{ids}")
    @Parameter(name = "ids", description = "消息ID", required = true)
    public AjaxResult markNotifyMessageRead(@NotNull(message = "消息ID不能为空") @PathVariable("ids") Long[] ids){
        docNotifyMessageService.markNotifyMessageRead(ids);
        return AjaxResult.success();
    }

    @Operation(summary = "获取公文信息")
    @GetMapping("/getDocument/{id}")
    @Parameter(name = "id", description = "消息ID", required = true)
    public AjaxResult<Document> getDocument(@NotNull(message = "消息ID不能为空") @PathVariable("id") Long id){
        return AjaxResult.success(docNotifyMessageService.getDocByMessageId(id));
    }
}
